<%@ page import="com.work.bean.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="com.work.entities.MyStudent" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/6
  Time: 15:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>我的学生</title>
</head>
<%@include file="teacher_common.jsp" %>
<script>
    $(function () {
        $("#my_student_li").attr('class', 'active');
    });
</script>
<style>
    th, td {
        width: 160px;
        padding: 10px;
        background-color: rgb(180, 193, 224);
    }
</style>

<%
    List<MyStudent> students = (List<MyStudent>) session.getAttribute("students");

    int pageNumber = (Integer) session.getAttribute("pageNumber");
    int whichPage = (Integer) session.getAttribute("whichPage");
    int countPage = (Integer) session.getAttribute("countPage");
    boolean flag = false;
    if (session.getAttribute("flag") != null) {
        flag = (Boolean) session.getAttribute("flag");
    }
//
//    String menuCategory = "";
//
//    if (session.getAttribute("typeName") != null) {
//        menuCategory = (String) session.getAttribute("typeName");
//    }

    if (session.getAttribute("error") != null) {
        out.print(session.getAttribute("error"));
    }

%>

<body>

<div>
    <div>
        <div style="margin-left: 250px">
            <h3 style="margin-top: 50px">学生列表</h3>
            <center><table border="1px" cellspacing="0px" cellpadding="20px" style="margin-left: 10px">
                <thead>
                <tr>
                    <th>学生名称</th>
                    <th>所在班级</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                <%

                    if (students != null) {
                        for (MyStudent student : students) {%>

                <tr>
                    <td><%=student.getUsername()%>
                    </td>
                    <td><%=student.getClassName()%>
                    </td>

                    <td>
                        <a href="#" onclick="deleteById(<%=student.getId()%>)">移除班级</a></td>
                </tr>

                <%
                    }
                } else {
                %>

                <tr>
                    <td colspan="4">暂无班级，可点击添加进行创建班级</td>
                </tr>
                <%
                    }
                %>

                <tr>
                    <td colspan="4" align="center">
                        <button onclick="jump('first')">最前页</button>
                        <button onclick="jump('last')">上一页</button>
                        <button onclick="jump('next')">下一页</button>
                        <button onclick="jump('final')">最后页</button>
                        跳转到第<select id="whichPage" onchange="jumpChange(0,this[selectedIndex].value)">
                        <%
                            if (pageNumber != 0) {

                                for (int i = 0; i < pageNumber; i++) {

                                    if ((i + 1) == whichPage) {
                        %>
                        <option selected="selected"><%=i + 1%>
                        </option>
                        <%
                        } else {%>
                        <option><%=i + 1%>
                        </option>
                        <%
                                    }
                                }

                            }
                        %>

                    </select>页
                        每页显示
                        <select id="pageCount" onchange="jumpChange(1,this[selectedIndex].value)">

                            <option><%=countPage%>
                            </option>
                            <%

                                for (int i = 3; i <= 15; i += 3) {
                                    if (i == countPage) {%>

                            <option selected="selected"><%=countPage%>
                            </option>
                            <%} else {%>
                            <option><%=i%>
                            </option>
                            <%
                                    }

                                }
                            %>
                        </select>条

                    </td>
                </tr>

                </tbody>
            </table>
            </center>
        </div>
        <!--//banner-->
    </div>
</div>

</body>

<script type="text/javascript">

    function deleteById(id) {

        if (confirm("确认移除？")) {
            window.location = "/my_student?id=" + id;
            alert("删除成功");
        }
    }

    function jump(type) {

        var objW = document.getElementById("whichPage"); //定位id
        var indexW = objW.selectedIndex; // 选中索引
        var whichPage = objW.options[indexW].text; // 选中文本

        var objP = document.getElementById("pageCount"); //定位id
        var indexP = objP.selectedIndex; // 选中索引
        var pageCount = objP.options[indexP].text; // 选中文本

        if (type == 'first') {

            if (whichPage == 1) {

                alert("当前已是第一页");

            } else {

                window.location = "/my_student?countPage=" + pageCount + "&whichPage=1";
            }

        } else if (type == 'last') {

            if (whichPage == 1) {
                alert("当前已是第一页");
            } else {

                window.location = "/my_student?countPage=" + pageCount + "&whichPage=" + (whichPage - 1);
            }

        } else if (type == 'next') {

            if (whichPage == <%=pageNumber%>) {

                alert("当前已是最后页");

            } else {

                window.location = "/my_student?countPage=" + pageCount + "&whichPage=" + (whichPage - (-1));
            }

        } else if (type == 'final') {

            if (whichPage == <%=pageNumber%>) {
                alert("当前已是最后页");
            } else {

                window.location = "/my_student?countPage=" + pageCount + "&whichPage=<%=pageNumber%>";
            }
        }

    }

    function jumpChange(type, value) {

        if (type == 0) {

            var objP = document.getElementById("pageCount"); //定位id
            var indexP = objP.selectedIndex; // 选中索引
            var pageCount = objP.options[indexP].text; // 选中文本

            window.location = "/my_student?countPage=" + pageCount + "&whichPage=" + value;

        } else if (type == 1) {

            var objW = document.getElementById("whichPage"); //定位id
            var indexW = objW.selectedIndex; // 选中索引
            var whichPage = objW.options[indexW].text; // 选中文本

            window.location = "/my_student?countPage=" + value + "&whichPage=1";

        }
    }

</script>
</html>
